package ${packageName}.${className_x}.controller;

import com.adolphor.base.controller.BaseController;
import com.adolphor.base.global.Wrapper;
import com.adolphor.base.utils.ParamCheck;
import ${packageName}.${className_x}.entity.${className_d};
import ${packageName}.${className_x}.entity.${className_d}Param;
import ${packageName}.${className_x}.entity.${className_d}Vo;
import ${packageName}.${className_x}.service.${className_d}Service;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/${className_s}")
public class ${className_d}Controller extends BaseController {

    @Autowired
    private ${className_d}Service ${className_x}Service;

    @RequestMapping("/query")
    public ${className_d}Vo query(@RequestBody ${className_d}Param param){
        param.setDeleted(0);
        return ${className_x}Service.query(param);
    }

    @RequestMapping("/query-list")
    public List<${className_d}Vo> queryList(@RequestBody @Nullable ${className_d}Param param){
        if (param == null) {
            param = new ${className_d}Param();
        }
        param.setDeleted(0);
        return ${className_x}Service.queryList(param);
    }

    @RequestMapping("/query-page")
    public PageInfo<${className_d}Vo> queryPage(@RequestBody ${className_d}Param param){
        param.setDeleted(0);
        return ${className_x}Service.queryPage(param);
    }

    @RequestMapping("/insert")
    public Wrapper insert(@RequestBody ${className_d} entity){
        entity.setDeleted(0);
        return Wrapper.ID(${className_x}Service.insert(entity));
    }

    @RequestMapping("/update")
    public Wrapper update(@RequestBody ${className_d} entity){
        ParamCheck.notBlank(entity.getId());
        entity.setDeleted(0);
        return Wrapper.COUNT(${className_x}Service.updateById(entity));
    }

    @RequestMapping("/save")
        public Wrapper save(@RequestBody ${className_d} entity){
        entity.setDeleted(0);
        return Wrapper.ID(${className_x}Service.save(entity));
    }

    @RequestMapping("/delete")
    public Wrapper delete(@RequestBody ${className_d} entity){
        return Wrapper.COUNT(${className_x}Service.delete(entity));
    }

    @RequestMapping("/delete-id")
    public Wrapper deleteById(@RequestParam String id){
        return Wrapper.COUNT(${className_x}Service.deleteById(id));
    }

    @RequestMapping("/delete-record-id")
    public Wrapper deleteRecordById(@RequestParam String id){
        return Wrapper.COUNT(${className_x}Service.deleteRecordById(id));
    }

    @RequestMapping("/delete-record")
    public Wrapper deleteRecord(@RequestBody ${className_d} entity){
        return Wrapper.COUNT(${className_x}Service.deleteRecord(entity));
    }

}